<?php ?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Dashboard :: salesianichioggia.it</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="shortcut icon" href="http://www.salesianichioggia.it/img/favicon.ico">
        <!-- Le styles -->
        <link href="../bootstrap/css/bootstrap.css" rel="stylesheet" />
        <link href="../bootstrap/css/bootstrap-responsive.css" rel="stylesheet" />
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
        <link rel="stylesheet" href="js/timepicker/jquery.ui.timepicker.css" />
        <style type="text/css">
            body {
                padding-top: 60px;
                padding-bottom: 40px;
                background: #f5f5f5 url('img/purty_wood.png') repeat;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
            .table {
                background-color: #FFF;
                line-height: 100%;
            }
            tbody > tr > td:last-child {
                width: 10%;
            }
        </style>


        <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
        <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
        <script src="js/timepicker/jquery.ui.timepicker.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#start_date, #end_date").datepicker({dateFormat:'dd/mm/yy',
                                                        dayNames: [ "Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdi", "Sabato" ],
                                                        monthNames: [ "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre" ],
                                                        dayNamesMin: [ "Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab" ],
                                                        firstDay: 1
                                                        });
                $("#start_time, #end_time").timepicker({showPeriodLabels:false,
                                                        hourText:'Ora',
                                                        minuteText:'Minuti'
                                                        });
                                                       
                $("#title").focus();
                $("form#event_form").submit(function(e){
                    
                    var error = false;
                    if (($("#start_date").val() != '') && 
                        ($("#start_time").val() != '') &&
                        ($("#end_date").val() != '') &&
                        ($("#end_time").val() != ''))
                    {
                        var start_date = $("#start_date").val();
                        var end_date = $("#end_date").val();
                        var start_time = $("#start_time").val();
                        var end_time = $("#end_time").val();

                        var sd_comps = start_date.split("/");
                        var ed_comps = end_date.split("/");

                        $("#start").val(sd_comps[2] + '-' + sd_comps[1] + '-' + sd_comps[0] + ' ' + start_time + ':00' );
                        $("#end").val(ed_comps[2] + '-' + ed_comps[1] + '-' + ed_comps[0] + ' ' + end_time + ':00');
                    } else {
                        error = error || true;
                       
                        $("#start_date, #start_time, #end_date, #end_time").parent().parent().addClass("error");
                        if ($("#start_time, #end_time").siblings("span.help-inline").length == 0) {
                            $("#start_time, #end_time").after('<span class="help-inline">Campi Obbligatori!</span>');
                        }
                    }
                   
                    if($("#title").val() == '') {
                        error = error || true;
                        $("#title").parent().parent().addClass("error");
                        if ($("#title").siblings("span.help-inline").length == 0) {
                            $("#title").after('<span class="help-inline">Campo Obbligatorio!</span>');
                        }
                    }
                    
                    if ($("select#type").val() == 'no-selection') {
                        error = error || true;
                        $("select#type").parent().parent().addClass("error");
                        if ($("select#type").siblings("span.help-inline").length == 0) {
                            $("select#type").after('<span class="help-inline">Campo Obbligatorio!</span>');
                        }
                    }
                    
                    return !error;

                });
                
                $("#start_date, #start_time, #end_date, #end_time, #title, #type").focus(function(){
                    $(this).parent().parent().removeClass("error");
                    $(this).parent().find("span.help-inline").remove(); 
                });

                $("a.delete").click(function(){
                    return confirm("Sei sicuro di voler eliminare l'evento?");
                });
            });
        </script>


        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    </head>
    <body>
        <?= HTMLManager::get_dashboard_navigation(unserialize($_SESSION['user'])) ?>
        <div class="container-fluid">
            <div class="row-fluid">
                <?= HTMLManager::get_dashboard_activities(unserialize($_SESSION['user'])) ?>

                <div class="span9">
                    <?php if ($_GET['action'] == ACTION_LIST) {
                        ?>
                        <h1>Eventi di <?php
                    $months = array('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
                    echo $months[$current_month - 1] . ' ' . $current_year;
                        ?></h1>
                        <a class="btn btn-primary" href="http://www.salesianichioggia.it/dashboard/event.php?action=list&month=<?= $prev_month ?>&year=<?= $prev_year ?>">Mese Precendente</a> <a class="btn btn-primary" href="http://www.salesianichioggia.it/dashboard/event.php?action=list&month=<?= $next_month ?>&year=<?= $next_year ?>">Mese Successivo</a>
                        <?php if (count($events) > 0) { ?>
                            <table class="table table-striped table-bordered" style="margin-top:10px;">
                                <thead>
                                    <tr>
                                        <td><strong>Titolo</strong></td>
                                        <td><strong>Descrizione</strong></td>
                                        <td><strong>Inizio</strong></td>
                                        <td><strong>Fine</strong></td>
                                        <td><strong>Tutto il Giorno</strong></td>
                                        <td><strong>Categoria</strong></td>
                                        <td><strong>Azioni</strong></td>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    foreach ($events as $event)
                                        $event->get_list_html();
                                    ?>
                                </tbody>
                            </table>

                            <?php
                        } else {
                            echo '<p>Non ci sono eventi programmati per questo mese!</p>';
                        }
                    } else if ($_GET['action'] == ACTION_NEW || $_GET['action'] == ACTION_EDIT) {
                        ?>
                        <form id="event_form" class="form-horizontal" method="POST" action="http://www.salesianichioggia.it/dashboard/event.php?action=save<?= ($event != null) ? '&id=' . $event->id : '' ?>">
                            <legend><?= ($_GET['action'] == ACTION_NEW) ? 'Nuovo Evento' : 'Modifica Evento' ?></legend>
                            <div class="control-group">
                                <label class="control-label" for="title">Titolo</label>
                                <div class="controls">
                                    <input  class="span12" type="text" id="title" placeholder="Titolo" name="title" value="<?= ($event != null) ? $event->title : '' ?>" />
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="description">Descrizione</label>
                                <div class="controls">
                                    <input class="span12" type="text" id="description" placeholder="Descrizione" name="description" value="<?= ($event != null) ? $event->description : '' ?>" />
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="start">Inizio</label>
                                <div class="controls">
                                    <input class="span3" type="text" id="start_date" placeholder="20/10/2012" value="<?= ($event != null) ? $event->start->format('d/m/Y') : '' ?>" />
                                    <input class="span3" type="text" id="start_time" placeholder="17:00" value="<?= ($event != null) ? $event->start->format('H:i') : '' ?>" />
                                    <input type="hidden" id="start" name="start" value="<?= ($event != null) ? $event->start->format('Y-m-d H:i:s') : '' ?>" />
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="end">Fine</label>
                                <div class="controls">
                                    <input class="span3" type="text" id="end_date" placeholder="20/10/2012" value="<?= ($event != null) ? $event->end->format('d/m/Y') : '' ?>" />
                                    <input class="span3" type="text" id="end_time" placeholder="17:00" value="<?= ($event != null) ? $event->end->format('H:i') : '' ?>" />
                                    <input type="hidden" id="end" name="end" value="<?= ($event != null) ? $event->end->format('Y-m-d H:i:s') : '' ?>" />
                                </div>
                            </div>
                            <div class="control-group">
                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" name="all_day" <?= ($event != null) && ($event->all_day) ? 'checked' : '' ?>> Tutto il giorno
                                    </label>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="type">Categoria</label>
                                <div class="controls">
                                    <?= $em->get_types_select(($event != null) ? $event->type_id : null) ?>
                                </div>
                            </div>


                            <div class="control-group">
                                <div class="controls">
                                    <button type="submit" class="btn btn-primary">Salva</button>
                                </div>
                            </div>
                        </form>
                        <?php
                    }
                    ?>
                </div>
            </div>
        </div>
        <script src="../bootstrap/js/bootstrap.js"></script>
        <script src="../bootstrap/js/bootstrap-transition.js"></script>
    </body>
</html>